/*
 * TrackChunk.hpp
 *
 *  Created on: 16 nov. 2010
 *      Author: guillaume
 */

#ifndef TRACKCHUNK_HPP_
#define TRACKCHUNK_HPP_

#include "Event.hpp"
#include <vector>

class TrackChunk {
public:
	TrackChunk();
	~TrackChunk();

	inline int getLength(){return length;};

	/**
	 * This method sets a trackChunk by creating a vector of Event. It uses setTrackChunksEvent
	 */
	void setTrackChunk(unsigned char* buffer);

	/**
	 * Set the length of the trackChunk by reading the 4 corresponding bytes
	 */

	void setTrackChunkLength(unsigned char* buffer);

	/**
	 * This method checks whether the 4 first byte of the trxkChunk are "MThd".
	 * It return 1 if the test is passed, otherwise returns 0
	 *
	 */
	bool integrityTest(unsigned char* buffer);

	/**
	 * Read and store a variable length quantity into an integer value
	 */
	int readVariableLength(unsigned char* buffer);

	/**
	 * Set the Event vector by pushing the correct event in it
	 * Uses setMidiEvent, setMetaEvent & setSysexEvent
	 */
	void setTrackChunkEvents(unsigned char* buffer);


	void setSysexEvent(unsigned char* buffer, int deltaTime);
	void setMidiEvent(unsigned char* buffer, int deltaTime, bool statusSetted);
	void setMetaEvent(unsigned char* buffer, int deltaTime);

	std::vector<Event*> eventVector;
	//Stores the status of the last midi event read
	int lastStatus;

private:
	int length;

};

#endif /* TRACKCHUNK_HPP_ */
